package com.qidian.mes.md.controller;

import com.qidian.mes.md.service.ContactService;
import com.qidian.mes.pojo.Contact;
import com.qidian.mes.util.pojo.QdResult;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author: CoolPro
 * @Description: 供应商联系方式控制类
 * @Time: 2024-04-12 00:25
 **/
@RestController
@CrossOrigin
@RequestMapping("/contact")
public class ContactController {
    @Autowired
    ContactService contactService;
    private final String SUPPORTER = "/sup";
    private final String CUSTOMER = "/cus";

    //添加
    @PostMapping(SUPPORTER + "/add")
    public QdResult addContact(@RequestBody Contact contact) {
        return contactService.addContact(contact);
    }

    //修改
    @PostMapping(SUPPORTER + "/update")
    public QdResult updateContact(@RequestBody Contact contact) {
        return contactService.updateContact(contact);
    }

    //删除
    @DeleteMapping(SUPPORTER + "/delete/{idSupport}")
    public QdResult deleteContact(@RequestBody Integer[] idContact, @PathVariable Integer idSupport) {
        return contactService.deleteContact(idContact, idSupport);
    }

    //根据供应商ID和联系人名称模糊查询
    @GetMapping(SUPPORTER + "/get")
    public QdResult getContacts(@RequestParam String name, @RequestParam Integer idSupport) {
        return contactService.getContacts(name, idSupport);
    }


    //客户联系方式
    @PostMapping(CUSTOMER + "/add")
    public QdResult addCustContact(@RequestBody Contact contact) {
        return contactService.addCustContact(contact);
    }

    //修改
    @PostMapping(CUSTOMER + "/update")
    public QdResult updateCustContact(@RequestBody Contact contact) {
        return contactService.updateCustContact(contact);
    }

    //删除
    @DeleteMapping(CUSTOMER + "/delete/{idSupport}")
    public QdResult deleteCustContact(@RequestBody Integer[] idContact, @PathVariable Integer idSupport) {
        return contactService.deleteCustContact(idContact, idSupport);
    }

    //根据供应商ID和联系人名称模糊查询
    @GetMapping(CUSTOMER + "/get")
    public QdResult getCustContacts(@RequestParam String name, @RequestParam Integer idSupport) {
        return contactService.getCustContacts(name, idSupport);
    }
}